﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class SubscribeShow : SkinnedWebControl
    {
        private Label lbTitle;
        private Label lbLinkMan;
        private Label lbEmail;
        private Label lbFax;
        private Label lbPhone;
        private Label lbMobile;
        private Label lbDescription;
        private Label lbDateCreated;
        private Label lbAddress;
        private Label lbPostalCode;

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            if (Info == null)
            {
                this.Visible = false;
                return;
            }

            lbTitle = (Label)skin.FindControl("lbTitle");
            lbLinkMan = (Label)skin.FindControl("lbLinkMan");
            lbEmail = (Label)skin.FindControl("lbEmail");
            lbFax = (Label)skin.FindControl("lbFax");
            lbPhone = (Label)skin.FindControl("lbPhone");
            lbMobile = (Label)skin.FindControl("lbMobile");
            lbDescription = (Label)skin.FindControl("lbDescription");
            lbDateCreated = (Label)skin.FindControl("lbDateCreated");
            lbAddress = (Label)skin.FindControl("lbAddress");
            lbPostalCode = (Label)skin.FindControl("lbPostalCode");

            if (lbTitle != null)
                lbTitle.Text = Info.Title;

            if (lbLinkMan != null)
                lbLinkMan.Text = Info.LinkMan;

            if (lbEmail != null)
                lbEmail.Text = Info.Email;

            if (lbFax != null)
                lbFax.Text = Info.Fax;

            if (lbPhone != null)
                lbPhone.Text = Info.Phone;

            if (lbMobile != null)
                lbMobile.Text = Info.Mobile;

            if (lbDescription != null)
                lbDescription.Text = Info.Content;

            if (lbDateCreated != null)
                lbDateCreated.Text = Globals.FormatDateTime(Info.DateCreated, DateTimeFormatMode.DateTime);

            if (lbAddress != null)
                lbAddress.Text = Info.Address;

            if (lbPostalCode != null)
                lbPostalCode.Text = Info.PostalCode;

            if (!Info.IsRead)
                Subscribe.IsRead();
        }

        private SubscribeInfo _info;
        public SubscribeInfo Info
        {
            get
            {
                if (_info == null)
                    _info = Subscribe.GetSubscribe(SiteContext.Current.Id);
                return _info;
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "Subscribe/SubscribeShow.ascx"; }
        }
    }
}
